package com.baselibrary.libs.Utils.windowSize;

import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;

import com.baselibrary.libs.Utils.log.LogUtils;

/**
 * Created by Administrator 于萌萌
 * 创建日期: 16:51 . 2017年02月15日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */

public class UtilsWindowSize {
    /**
     * 获取屏幕分辨率
     * @param activity
     *  sum[0] = displayMetrics.widthPixels; 宽
     *  sum[1]  = displayMetrics.heightPixels; 高
    LogUtils.i("尺寸是"+"\t宽\t"+sum[0]+"\t高\t"+sum[1]);
     * @return
     */
    public static int[] getSize(Activity activity){
        int[] sum = new int[2];
        DisplayMetrics displayMetrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        sum[0] = displayMetrics.widthPixels;
        sum[1]  = displayMetrics.heightPixels;
        LogUtils.i("尺寸是"+"\t宽\t"+sum[0]+"\t高\t"+sum[1]);
        return sum;
    }

    /**
     * 按比例缩放
     * @param activity
     * @param view
     * @param f 范围 1 - 100
     */
    public static void setSize(Activity activity, View view,int f){
        if (f>=100){
            f = 100;
        }else if(f<=0){
            f = 1;
        }

        int[] size = getSize(activity);
        int i = size[1];
        ViewGroup.LayoutParams params = view .getLayoutParams();
        float i1 = (float)f / 100;
        LogUtils.i("现在比例是"+i1);
        params.height = (int) (i*i1+0.5f);

        view.setLayoutParams(params);
    }
}
